export default {
  namespace: 'basicDataModel',

  state: {
    data: [{ text: '范例1', id: 1 }],
  },

  effects: {
    *add({ payload }, { call, put, select }) {
      const oldData = yield select((state) => state.basicDataModel.data);
      const lastID = oldData[oldData.length - 1].id;
      const appendData = {
        id: lastID + 1,
        text: payload.text,
      };
      const newData = [...oldData];
      newData.push(appendData);
      yield put({
        type: 'save',
        payload: { data: newData },
      });
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
